<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	
</style>
<div class="page-header">
	<h1>
		收件箱
		<small>
			<a href="<?=admin_url('mail/mail_edit')?>" class="blue ml10">
				<i class="ace-icon fa fa-plus"></i> 写信
			</a>
		</small>
	</h1>
</div>

<div class="col-xs-12">
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>邮件标题</th>
				<th>发件人</th>
				<th>邮件附件</th>
				<th>发送时间</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	$(function(){
		// 邮件表格
		var table =$('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('mail/get_mail_list')?>',
			"columns": [
	            {"data": "mail_title"},
	            {"data": function(ret){
	            	return '<a href="javascript:;" data-id="'+ ret.id +'" class="show-mail-user"><i class="fa fa-user"></i> 查看收件人</a>';
	            }},
	            {"data": function(ret){
	            	return ret.hasAttachment ? '<span class="label label-success mr10"><i class="ace-icon fa fa-paperclip"></i> '+ ret.hasAttachment +'个附件</span>' : '';
	            }},
	            {"data": "createtime"},
	            {"data": function(ret){
	            	var action = '';
	            	action += '<a class="mr20" href="<?=admin_url('mail/mail_info')?>/'+ ret.id +'?menu_link=<?=$menuLink?>"><i class="fa fa-envelope"></i> 查看</a>';
	                return action;
	            }},
			]
		});

		// 删除文章
		$("body").on("click", ".delete-mail", function(e){
			var id = $(this).data("id");
			layer.confirm('确定删除该邮件吗？', function(){
				// 提交数据
				var postUrl = "<?=admin_url('mail/delete_mail_action')?>";
				var postData = {"id": id};
				ajax_post(postUrl, postData, function(res){
					table.draw();
				})
			});
		})

		// 显示邮件收件人
		$("body").on("click", ".show-mail-user", function(){
			var id = $(this).data("id");
			// 获取收件人列表
			var getUserUrl = "<?=admin_url('mail/get_mail_user')?>";
			var params = {
				"id": id,
				"hideLoading": true
			};
			ajax_get(getUserUrl, params, function(res) {
				var userList = "";
				for(var i in res.data) {
					var user = res.data[i];
					userList += '<div class="itemdiv memberdiv">\
						<div class="inline pos-rel">\
							<div class="user">\
								<a href="javascript:;"><img src="'+ user.image +'" alt="'+ user.name +'"></a>\
							</div>\
							<div class="body">\
								<div class="name"><a href="javascript:;">'+ user.name +'</a></div>\
							</div>\
						</div>\
					</div>';
				}
				$("#mail-user-div").html(userList);
				// 显示弹窗
				$("#modal-user").modal();
			})
		})
	})
</script>